/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package models;

import GUI.gui_main;
import java.awt.MouseInfo;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author wesley
 * 
 * class for creating a new thread which moves the wii-remote image up-and-down
 */
public class MoveRemoteThread extends Thread {
    int mouseX;
    int mouseY;

    public MoveRemoteThread(gui_main GMain) {
         mouseX = MouseInfo.getPointerInfo().getLocation().x;
         mouseY = MouseInfo.getPointerInfo().getLocation().y;
        
        run(GMain);
    }

   
    public void run(gui_main main) {
        
        try {
            
            
            //SPECIFY THE LABEL OBJECT FOR "Startup.jLabel1"
            int x = main.labelWiiRemote.getX();
            
            
            //ga oneindig door met het: 1) label omhoog zetten 2) label omlaag zetten
            for (int a = 0; a == 0; a = 0){
            for (int i = 110; i > 0; i--){
                main.labelWiiRemote.setLocation(x, i);
                this.checkMouse(main);
                Thread.sleep(10);
            }
            for (int i = 0; i < 110; i++){
                main.labelWiiRemote.setLocation(x, i);
                this.checkMouse(main);
                Thread.sleep(10);
            }
               
                
            }
        
         } catch (InterruptedException ex) {
             //will always be throwed if thread.sleep is interrupted: do nothing
         }
        
        
    }
    
      public void checkMouse(gui_main GMain){
          
        int verschilX = MouseInfo.getPointerInfo().getLocation().x - this.mouseX;
        int verschilY = MouseInfo.getPointerInfo().getLocation().y - this.mouseY;
        
        GMain.pannelGraphic.setLocation(GMain.pannelGraphic.getLocation().x+verschilX, 
                                        GMain.pannelGraphic.getLocation().y+verschilY);
        GMain.pannelGraphic.revalidate();
        
        this.mouseX = MouseInfo.getPointerInfo().getLocation().x;
        this.mouseY = MouseInfo.getPointerInfo().getLocation().y;
        
        if(GMain.pannelGraphic.getLocation().y < -350){
            for(int i=-350; i>-1000; i-=5){
                GMain.pannelGraphic.setLocation(GMain.pannelGraphic.getLocation().x, i);
                try {
                    Thread.sleep(10);
                } catch (InterruptedException ex) {
                    Logger.getLogger(MoveRemoteThread.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
           GMain.pannelGraphic.setVisible(false);
           this.interrupt();
           
           

           
        }
      }
}